<!--
* description: 采购销退申请单业务审核
* author: wangjuan
* createdDate:2021-3-1
-->
<template>
  <section class="editpurchaseBusinessAudit">
    <el-dialog
      v-dialogDrag
      :visible.sync="curPopupsVisible"
      :title="textMap[popupsState]"
      :append-to-body="true"
      width="70%"
      :close-on-click-modal="false"
      @close="closeEdit"
    >
      <dialogHeader
        slot="title"
        :title="titleName"
        :style-type="$store.state.app.dialogType"
      />

      <div class="app-container app-container-table">
        <one-table-template
          ref="multipleTable"
          :key="oneTableKey"
          :dynamic-buttons="tableButtons"
          :dynamic-components="tableComponents"
          :dynamic-api-config="apiConfig"
          :dynamic-table-cols="tableCols"
          :dynamic-form-fields="formField"
          :dynamic-is-show-select="false"
          :dynamic-is-init-table="true"
          :dynamic-table-defult-height="300"
        />
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import { formMixins } from '@/components/mixins/formMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/pa/procuremenData'

export default {
  components: {
    dialogHeader: () => import('@/components/dialogHeader'),
    OneTableTemplate
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins, formMixins],

  props: {
    dynamicEditRowData: { type: Object, default: () => { return {} } },
    // 弹出是否显示
    popupsVisible: { type: Boolean, default: false },
    customObj: { type: Object, default: () => { return {} } }
  },

  data() {
    const viewPageCode = 'purchaseBusiness-Edit'
    return {
      titleName: '销退申请单业务审核',
      apiConfig: api.purchasePinBackBusinessQueryDetail,
      // 动态组件-按钮

      tableButtons: [
        {
          compKey: 'btnKey1',
          size: 'small',
          name: 'adopt',
          icon: 'iconfont  icon-adopt',
          clickEvent: () => this.pass(),
          text: '通过'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reject',
          icon: 'iconfont  icon-reject',
          clickEvent: () => this.reject(),
          text: '驳回'
        },
        {
          compKey: 'btnKey3',
          type: 'primary',
          size: 'small',
          clickEvent: () => null,
          text: '查看附件',
          position: 'left'
        }
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode] &&
          this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[viewPageCode].formComponents
          : [
            {
              compKey: 'compKey1',
              labelName: '销退类型：',
              codeField: 'purReturnTypeName',
              component: () => import('@/components/org/LookupValue'),
              type: 'dropdownList',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '销退单号：',
              codeField: 'purReturnCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '销退日期：',
              codeField: 'returnDate',
              component: () => import('@/components/org/commonInput'),
              dateType: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '入库单号：',
              codeField: 'inStoreCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '网点编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey6',
              labelName: '网点名称：',
              codeField: 'dlrShortName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey7',
              labelName: '销退总金额',
              codeField: 'returnAmount',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey8',
              labelName: '销退原因：',
              codeField: 'returnReason',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              disabled: true,
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey9',
              labelName: '审核意见：',
              codeField: 'businessAuditOpinion',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true,
              span: 12
            }
          ],

      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'partId',
              label: '备件ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'purReturnDId ',
              label: '子单ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'partNo',
              label: '备件编码'
            },
            {
              prop: 'partName',
              label: '备件名称'
            },
            {
              prop: 'inStoreQty',
              label: '入库数量'
            },
            {
              prop: 'optionalPagName',
              label: '入库异常数量',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'carColorName',
              label: '入库异常原因',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'inventoryQuantity',
              label: '库存数量'
            },
            {
              prop: 'returnQty',
              label: '销退数量'
            },
            {
              prop: 'returnPrice',
              label: '销退单价'
            },
            {
              prop: 'returnAmount',
              label: '销退金额'
            },
            {
              prop: 'warehouseName',
              label: '仓库'
            },
            {
              prop: 'placeCode',
              label: '库位'
            }
          ],

      formField: {
        purReturnType: '',
        purReturnTypeName: '',
        purReturnCode: '',
        dlrCode: '',
        dlrShortName: '',
        returnDate: '',
        returnReason: '',
        purReturnId: '',
        updateControlId: '',

        partNo: '',
        partName: '',
        businessAuditOpinion: '',
        inStoreQty: '',
        inventoryQuantity: '',
        returnQty: '',
        returnPrice: '',
        returnAmount: '',
        warehouseName: '',
        placeCode: '',
        partId: '',
        purReturnDId: ''
      }
    }
  },
  watch: {
  },

  mounted() {
  },

  methods: {

    // 通过
    pass() {
      const that = this
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: api.purchasePinBackBusinessPass,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          businessAuditOpinion: that.formField.businessAuditOpinion,
          purReturnId: that.formField.purReturnId,
          updateControlId: that.formField.updateControlId
        }

      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: response.msg,
            type: 'success',
            duration: 1000
          })
          this.$emit('update:popupsVisible', false)
          this.$nextTick(() => {
            this.$parent.queryTable(1)
          })
        } else {
          this.$message({
            message: response.msg,
            type: 'warn',
            duration: 1000
          })
        }
      })
    },

    // 驳回
    reject() {
      const that = this
      const queryObj = {
        // 保存mutation
        type: 'mutation',
        // api配置
        apiConfig: api.purchasePinBackBusinessOverrule,
        // 条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          businessAuditOpinion: that.formField.businessAuditOpinion,
          purReturnId: that.formField.purReturnId,
          updateControlId: that.formField.updateControlId
        }

      }
      // 转换了中台请求格式数据
      var paramD = this.$getParams(queryObj)
      // 调用中台API方法（可复用）
      this.$requestAPI(paramD).then(response => {
        if (response.result === '1') {
          this.$message({
            message: response.msg,
            type: 'success',
            duration: 1000
          })
          this.$emit('update:popupsVisible', false)
          this.$nextTick(() => {
            this.$parent.queryTable(1)
          })
        } else {
          this.$message({
            message: response.msg,
            type: 'warn',
            duration: 1000
          })
        }
      })
    },
    closeEdit() {
      this.$emit('update:popupsVisible', false)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
